/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package plum.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;

import plum.ChoiceValue;
import plum.DefaultSelectChoiceValueAction;
import plum.PlumPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Default Select Choice Value Action</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link plum.impl.DefaultSelectChoiceValueActionImpl#getSelectedQuery <em>Selected Query</em>}</li>
 *   <li>{@link plum.impl.DefaultSelectChoiceValueActionImpl#getSelected <em>Selected</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DefaultSelectChoiceValueActionImpl extends ActionImpl implements DefaultSelectChoiceValueAction {
	/**
	 * The default value of the '{@link #getSelectedQuery() <em>Selected Query</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSelectedQuery()
	 * @generated
	 * @ordered
	 */
	protected static final String SELECTED_QUERY_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getSelectedQuery() <em>Selected Query</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSelectedQuery()
	 * @generated
	 * @ordered
	 */
	protected String selectedQuery = SELECTED_QUERY_EDEFAULT;

	/**
	 * The cached value of the '{@link #getSelected() <em>Selected</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSelected()
	 * @generated
	 * @ordered
	 */
	protected EList<ChoiceValue> selected;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DefaultSelectChoiceValueActionImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return PlumPackage.Literals.DEFAULT_SELECT_CHOICE_VALUE_ACTION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getSelectedQuery() {
		return selectedQuery;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSelectedQuery(String newSelectedQuery) {
		String oldSelectedQuery = selectedQuery;
		selectedQuery = newSelectedQuery;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, PlumPackage.DEFAULT_SELECT_CHOICE_VALUE_ACTION__SELECTED_QUERY, oldSelectedQuery, selectedQuery));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ChoiceValue> getSelected() {
		if (selected == null) {
			selected = new EObjectResolvingEList<ChoiceValue>(ChoiceValue.class, this, PlumPackage.DEFAULT_SELECT_CHOICE_VALUE_ACTION__SELECTED);
		}
		return selected;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case PlumPackage.DEFAULT_SELECT_CHOICE_VALUE_ACTION__SELECTED_QUERY:
				return getSelectedQuery();
			case PlumPackage.DEFAULT_SELECT_CHOICE_VALUE_ACTION__SELECTED:
				return getSelected();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case PlumPackage.DEFAULT_SELECT_CHOICE_VALUE_ACTION__SELECTED_QUERY:
				setSelectedQuery((String)newValue);
				return;
			case PlumPackage.DEFAULT_SELECT_CHOICE_VALUE_ACTION__SELECTED:
				getSelected().clear();
				getSelected().addAll((Collection<? extends ChoiceValue>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case PlumPackage.DEFAULT_SELECT_CHOICE_VALUE_ACTION__SELECTED_QUERY:
				setSelectedQuery(SELECTED_QUERY_EDEFAULT);
				return;
			case PlumPackage.DEFAULT_SELECT_CHOICE_VALUE_ACTION__SELECTED:
				getSelected().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case PlumPackage.DEFAULT_SELECT_CHOICE_VALUE_ACTION__SELECTED_QUERY:
				return SELECTED_QUERY_EDEFAULT == null ? selectedQuery != null : !SELECTED_QUERY_EDEFAULT.equals(selectedQuery);
			case PlumPackage.DEFAULT_SELECT_CHOICE_VALUE_ACTION__SELECTED:
				return selected != null && !selected.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (selectedQuery: ");
		result.append(selectedQuery);
		result.append(')');
		return result.toString();
	}

} //DefaultSelectChoiceValueActionImpl
